package com.homedo.microservice.open.service.gateway.manager.web.gateway.persistence.dao;

import com.homedo.common.bean.vo.Pagination;
import com.homedo.common.dao.BaseDao;
import com.homedo.common.util.Detect;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.bean.po.RouteVersion;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.bean.query.RouteVersionQuery;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.persistence.mapper.IRouteVersionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;


/**
 * @author 作者 jgshun
 * @date 创建时间 2018年09月19日 17时16分40秒
 */
@Repository
public class RouteVersionDao extends BaseDao<RouteVersion> {
    @Autowired
    private IRouteVersionMapper routeVersionMapper;

    public Pagination<RouteVersion> getPagination(RouteVersionQuery routeVersionQuery, Pagination<RouteVersion> pagination) {
        Example example = new Example(RouteVersion.class);
        Example.Criteria criteria = example.createCriteria();

        if (Detect.notEmpty(routeVersionQuery.getRouteIds())) {
            criteria.andIn(RouteVersion.FIELD_ROUTEID, routeVersionQuery.getRouteIds());
        }
        if (Detect.notEmpty(routeVersionQuery.getServiceIds())) {
            criteria.andIn(RouteVersion.FIELD_SERVICEID, routeVersionQuery.getServiceIds());
        }

        return super.getPagination(pagination, example);
    }

    public List<RouteVersion> getListByRouteIds(List<String> routeIds) {
        Example example = new Example(RouteVersion.class);
        example.createCriteria().andIn(RouteVersion.FIELD_ROUTEID, routeIds);
        example.setOrderByClause(RouteVersion.ORDER_CREATE_TIME_DESC);

        return super.getListByExample(example);
    }
}
